package com.qianyu;

import java.util.*;

/**
 * @author Administrator
 */
class Solution {
    public int[] constructArr(int[] arr) {
        if (arr == null || arr.length == 0) {
            return new int[0];
        }
        int[] res = new int[arr.length];
        res[0] = 1;
        int temp = 1;
        for (int i = 1; i < arr.length; i++) {
            res[i] = res[i - 1] * arr[i - 1];
        }
        for (int i = arr.length - 2; i >= 0; i--) {
            temp *= arr[i + 1];
            res[i] *= temp;
        }
        return res;
    }

    public static void main(String[] args) {
        Solution s = new Solution();
        int[] arr = s.constructArr(new int[]{1, 2, 3, 4, 5});
        System.out.println(Arrays.toString(arr));
    }
}